package com.hubt.controller;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hubt.common.PageBean;
import com.hubt.service.PtRoleService;
import com.hubt.vo.Linkvo;
import com.hubt.vo.RoleVo;

import net.sf.jsqlparser.statement.update.Update;

@Controller
@RequestMapping("/role")
public class PtRoleController {

	@Autowired
	private PtRoleService ptRoleService;
	
	@RequestMapping(value = "/getRoles",method = RequestMethod.GET)
	@ResponseBody
	public PageBean<RoleVo> finadbypage(@Param("pageSize") Integer pageSize,@Param("pageNumber") Integer pageNumber){
		PageBean<RoleVo> pageBean=new PageBean<RoleVo>();
		pageBean=ptRoleService.findbyPage(pageNumber, pageSize);
		return pageBean;
	}
	
	
	@RequestMapping(value = "/insert",method = RequestMethod.POST)
	@ResponseBody
	public int insert(@Param("form")RoleVo roleVo) {
		return ptRoleService.insert(roleVo);
	}
	
	
	@RequestMapping(value = "/update",method = RequestMethod.POST)
	@ResponseBody
	public int Update(@Param("form") RoleVo roleVo) {
		return ptRoleService.update(roleVo);
	}
	
	@RequestMapping(value = "/getRole",method = RequestMethod.GET)
	@ResponseBody
	public RoleVo findById(@Param("uuid") String uuid) {
		RoleVo roleVo=new RoleVo();
		roleVo=ptRoleService.findbyId(uuid);
		return roleVo;
	}
	
	@RequestMapping(value = "/getResources",method = RequestMethod.GET)
	@ResponseBody
	public List<String> getResources(@Param("roleId")String roleId){
		return ptRoleService.getResources(roleId);
	}
	@RequestMapping("/linkResource")
	@ResponseBody
	public int linRes(Linkvo linkvo) {
		System.out.println(linkvo.getRoleId());
		System.out.println(linkvo.getResources());
return ptRoleService.linkRes(linkvo);
	}
	
	@RequestMapping(value = "/remove",method = RequestMethod.GET)
	@ResponseBody
	public int delete(@Param("id") String id) {
		return ptRoleService.remove(id);
	}
	
	
	@RequestMapping("/getRoles2")
	@ResponseBody
	public List<RoleVo> getRole2(){
		return ptRoleService.findAll();
	}
}
